//
//  TXP_LeftViewController.m
//  StayAwhile
//
//  Created by dllo on 16/1/27.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "TXP_LeftViewController.h"
#import "TXP_HeaderView.h"
#import "TXPRadioPageViewController.h"
#import "TXPLandPageViewController.h"
@interface TXP_LeftViewController ()<UITableViewDelegate,UITableViewDataSource, TXP_HeaderViewDelegate>
@property (nonatomic,strong)NSArray *allArray;
@property (nonatomic,strong)UITableView *myTableView;
@property (nonatomic, strong) TXP_HeaderView *header;
@end

@implementation TXP_LeftViewController
- (void)viewWillAppear:(BOOL)animated{
    
    [super viewWillAppear:animated];
    BmobUser *bUser = [BmobUser getCurrentUser];
    if (bUser) {
        NSString *name = [bUser objectForKey:@"username"];
        [self.header.loadBtn setTitle:name forState:UIControlStateNormal];
        NSLog(@"%@", name);
    } else {
        [self.header.loadBtn setTitle:@"登录/注册" forState:UIControlStateNormal];
    }

     [self.myTableView selectRowAtIndexPath:[NSIndexPath indexPathForItem:0 inSection:0] animated:NO scrollPosition:UITableViewScrollPositionTop];
    
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.allArray = @[@"首页",@"电台",@"阅读",@"碎片", @"下载", @"收藏", @"设置"];
    self.myTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 414, HEIGHT - 60) style:UITableViewStyleGrouped];
    [self.myTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell"];
    self.myTableView.delegate = self;
    self.myTableView.dataSource = self;
    self.myTableView.backgroundColor = RGBA(39, 39, 39, 1);
    [self.view addSubview:self.myTableView];
    UIImageView *myImgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, self.myTableView.frame.size.height, 414, 160)];
    myImgView.backgroundColor = RGBA(29, 29, 29, 1);
    [self.view addSubview:myImgView];

}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    
    return 180;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    self.header = [[TXP_HeaderView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 180)];
    self.header.headerViewdelegate = self;
    self.header.backgroundColor = [UIColor clearColor];
    
    return self.header;
}
// 点击跳到登陆页面
- (void)clickButtonPushToLoadPage{
    TXPLandPageViewController *landPageVC = [[TXPLandPageViewController alloc] init];
    [self.navigationController pushViewController:landPageVC animated:YES];
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    return self.allArray.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
    cell.textLabel.text = self.allArray[indexPath.row];
    cell.textLabel.textColor = [UIColor whiteColor];
    cell.backgroundColor = [UIColor clearColor];
    cell.selectionStyle = UITableViewCellSelectionStyleGray;
    
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    if (indexPath.row==1) {
        TXPRadioPageViewController *radioPage = [[TXPRadioPageViewController alloc] init];
        
        [self.navigationController pushViewController:radioPage animated:YES];
    }
    
    NSLog(@"点击成功");
    
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
